/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.com.jsepc.rep.catalog;

import cn.com.jsepc.rep.comm.ConstUtil;
import com.jarp.db.DAO;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import net.sf.json.JSONObject;

/**
 *
 * @author 赵远
 */
public class Catalog_Check {
	
	public String delete_check(String cataid){
		DAO dao=new DAO();
		String sql="select * from tb_catalog t where t.parentcataid="+cataid;
		try {
			Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
			if(v!=null){
				return "no";
			}
			else{
				return "ok";
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
		
		return "error";
	}
    public String check(String itemJsonInfo){
    	JSONObject jsonObject = new JSONObject(itemJsonInfo);
        String CATANAME=jsonObject.getString("CATANAME");
        String CATANO=jsonObject.getString("CATANO");
        String sql="select CATAID from tb_catalog where CATANAME='"+CATANAME+"' or CATANO='"+CATANO+"'" ;
        DAO dao=new DAO();
        try {
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if(v==null){
                return "ok";
            }
            else
                    return "wrong";
        } catch (ServletException ex) {
            Logger.getLogger(Catalog_Check.class.getName()).log(Level.SEVERE, null, ex);
            return "wrong";
        }
    }
    
    public String check(String cataid,String itemJsonInfo){
    	JSONObject jsonObject = new JSONObject(itemJsonInfo);
        String CATANAME=jsonObject.getString("CATANAME");
        String CATANO=jsonObject.getString("CATANO");
        String sql="select CATAID from tb_catalog where  CATAID!="+cataid+" and (CATANAME='"+CATANAME+"' or CATANO='"+CATANO+"')";
        DAO dao=new DAO();
        try {
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if(v==null){
                return "ok";
            }
            else
                    return "wrong";
        } catch (ServletException ex) {
            Logger.getLogger(Catalog_Check.class.getName()).log(Level.SEVERE, null, ex);
            return "wrong";
        }
    }
    
    public String check_report(String cataid){
        String sql="select * from tb_report where cataid="+cataid;
        DAO dao=new DAO();
        try {
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if(v==null){
                return "ok";
            }
            else
                    return "wrong";
        } catch (ServletException ex) {
            Logger.getLogger(Catalog_Check.class.getName()).log(Level.SEVERE, null, ex);
            return "wrong";
        }
    }
    
}
